package com.ruoyi.comment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comment.domain.TbComment;
import com.ruoyi.comment.service.ITbCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价管理Controller
 * 
 * @author txt
 * @date 2025-02-08
 */

@Api("评价信息管理")
@RestController
@RequestMapping("/comment/comment")
public class TbCommentController extends BaseController
{
    @Autowired
    private ITbCommentService tbCommentService;

    /**
     * 查询评价管理列表
     */
    @ApiOperation(value = "评价列表")
    @GetMapping("/list")
    public TableDataInfo list(TbComment tbComment)
    {
        startPage();
        List<TbComment> list = tbCommentService.selectTbCommentList(tbComment);
        return getDataTable(list);
    }

    /**
     * 导出评价管理列表
     */
    @Log(title = "评价管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbComment tbComment)
    {
        List<TbComment> list = tbCommentService.selectTbCommentList(tbComment);
        ExcelUtil<TbComment> util = new ExcelUtil<TbComment>(TbComment.class);
        util.exportExcel(response, list, "评价管理数据");
    }

    /**
     * 获取评价管理详细信息
     */
    @ApiOperation(value = "通过id拿到评价")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCommentService.selectTbCommentById(id));
    }

    /**
     * 新增评价管理
     */
    @ApiOperation(value = "增加评价")
    @Log(title = "评价管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbComment tbComment)
    {
        return toAjax(tbCommentService.insertTbComment(tbComment));
    }

    /**
     * 修改评价管理
     */
    @ApiOperation(value = "修改评价管理")
    @Log(title = "评价管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbComment tbComment)
    {
        return toAjax(tbCommentService.updateTbComment(tbComment));
    }

    /**
     * 删除评价管理
     */
    @ApiOperation(value = "删除评价管理")
    @Log(title = "评价管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCommentService.deleteTbCommentByIds(ids));
    }
}
